﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZDSoft.LMS.Core;
using ZDSoft.LMS.Service;
using ZDSoft.LMS.Domain;
using ZDSoft.LMS.Web.Apps;

namespace ZDSoft.LMS.Web.Controllers
{
    public class TranportOrderController : UcController
    {
        //
        // GET: /TranportOrder/

        public ActionResult Index()
        {
            var listAll = Container.Instance.Resolve<ITranportOrderService>().GetAll();
            return View(listAll);
        }

        //
        // GET: /TranportOrder/Details/5

        public ActionResult Details(int id)
        {
            var tranportOrder = Container.Instance.Resolve<ITranportOrderService>().Get(id);
            return View(tranportOrder);
        }

        //
        // GET: /TranportOrder/Create

        public ActionResult Create()
        {
            TransportOrder order = new TransportOrder();
            order.TranportOrderItems = new List<TransportOrderItem>();
            order.TranportOrderItems.Add(new TransportOrderItem());
            order.TranportOrderItems.Add(new TransportOrderItem());
            return View(order);
        }

        //
        // POST: /TranportOrder/Create

        [HttpPost]
        public ActionResult Create(TransportOrder tranportOrder)
        {
            //try
            //{
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    tranportOrder.Creator = AppHelper.LoginedUser;
                    Container.Instance.Resolve<ITranportOrderService>().Create(tranportOrder);
                    return RedirectToAction("Index");
                }
                return View();
            //}
            //catch
            //{
            //    return View();
            //}
        }

        //
        // GET: /TranportOrder/Edit/5

        public ActionResult Edit(int id)
        {
            var tranportOrder = Container.Instance.Resolve<ITranportOrderService>().Get(id);
            return View(tranportOrder);
        }

        //
        // POST: /TranportOrder/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, TransportOrder tranportOrder)
        {
            try
            {
                // TODO: Add update logic here
                Container.Instance.Resolve<ITranportOrderService>().Update(tranportOrder);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /TranportOrder/Delete/5

        public ActionResult Delete(int id)
        {
            try
            {
                // TODO: Add delete logic here
                Container.Instance.Resolve<ITranportOrderService>().Delete(id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // POST: /TranportOrder/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, TransportOrder tranportOrder)
        {
            try
            {
                // TODO: Add delete logic here
                Container.Instance.Resolve<ITranportOrderService>().Delete(id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
